﻿using Common.DictComponent;
using Microsoft.EntityFrameworkCore;
using Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace DAL
{
    public class AppDbContext:DbContext,IDbContext
    {
        private string URL;

        public AppDbContext()
        {
            dynamic jsonObject = JsonConvert.DeserializeObject(File.ReadAllText("appsettings.json"));
            URL = jsonObject.ConnectionStrings.SqlServer;
        }
        /// <summary>
        /// 构造函数，接收数据库上下文配置选项并传递给基类
        /// 配置选项通常包含数据库连接字符串、数据库提供程序等信息
        /// </summary>
        /// <param name="options">数据库上下文配置选项，由依赖注入容器提供</param>
        public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }


        /// <summary>
        /// 编号规则
        /// </summary>
        public DbSet<NumberingRule> NumberingRule { get; set; }

        //protected override void OnModelCreating(ModelBuilder modelBuilder)
        //{
        //    modelBuilder.Entity<NumberingRule>(entity =>
        //    {
        //        entity.Property(e => e.RuleId)
        //              .IsRequired()
        //              .HasColumnType("bigint");
        //    });
        //}
        /// <summary>
        /// 字典类型
        /// </summary>
        public DbSet<WmsDictType> WmsDictType { get; set; }

        /// <summary>
        /// 字典数据
        /// </summary>
        public DbSet<WmsDictData> WmsDictData { get; set; }

        /// <summary>
        /// 功能模块
        /// </summary>
        public DbSet<GroupMenu> groupManagers { get; set; }
        /// <summary>
        /// 子模块
        /// </summary>
        public DbSet<Jurisdiction> jurisdictions { get; set; }
        /// <summary>
        /// 角色关联
        /// </summary>
        public DbSet<UserRoles> userRoles { get; set; }
        /// <summary>
        /// 权限关联
        /// </summary>
        public DbSet<RolesJurisdiction> rolesJurisdictions { get; set; }
        /// <summary>
        /// 层级菜单
        /// </summary>
        public DbSet<Model.CJurisdiction> cJurisdictions { get; set; }
        /// <summary>
        /// 用户
        /// </summary>
        public DbSet<Model.Users> users { get; set; }
        /// <summary>
        /// 登陆
        /// </summary>
        public DbSet<Model.UserRoleView> userRoleView { get; set; }

        /// <summary>
        /// 货品类型
        /// </summary>
        public DbSet<GoodsType> goodsTypes { get; set; }

        /// <summary>
        /// 客户
        /// </summary>
        public DbSet<BiCustomer> biCustomer { get; set; }
        /// <summary>
        /// 供应商
        /// </summary>
        public DbSet<BiSupplier> biSupplier { get; set; }
        /// <summary>
        /// 进货订单
        /// </summary>
        public DbSet<OmPurchaseOrderDTO> OmPurchaseOrderDTO { get; set; }
        /// <summary>
        /// 客户
        /// </summary>
        public DbSet<BiCustomer> BiCustomer { get; set; }
        // 销售退货单表
        public DbSet<OmSalesReturn> OmSalesReturn { get; set; }

        // 销售订单明细表
        public DbSet<OmSalesOrderDetail> OmSalesOrderDetail { get; set; }

        // 销售订单表
        public DbSet<OmSalesOrder> OmSalesOrder { get; set; }

        // 采购退货明细表
        public DbSet<OmPurchaseReturnDetail> OmPurchaseReturnDetail { get; set; }

        // 采购退货表
        public DbSet<OmPurchaseReturn> OmPurchaseReturn { get; set; }

        // 采购订单明细表
        public DbSet<OmPurchaseOrderDetail> OmPurchaseOrderDetail { get; set; }

        // 仓库表
        public DbSet<BiWarehouse> BiWarehouse { get; set; }

        // 交易类型表
        public DbSet<BiTransactionType> BiTransactionType { get; set; }

        // 货品表
        public DbSet<BiProduct> BiProduct { get; set; }

        //供应商
        public DbSet<BiSupplier> BiSupplier { get; set; }
        //用户表
        public DbSet<Users> Users { get; set; }
        //组织机构
        public DbSet<SysOrganization> SysOrganization { get; set; }

        //附件
        public DbSet<SysAttachment> SysAttachment { get; set; }
        /// <summary>
        /// 批次
        /// </summary>
        public DbSet<WhBatch> WhBatch { get; set; }
        /// <summary>
        /// 仓库
        /// </summary>
        public DbSet<WhInventory> WhInventory { get; set; }
        /// <summary>
        /// 库位
        /// </summary>
        public DbSet<WhLocation> WhLocation { get; set; }
        /// <summary>
        /// 入库单
        /// </summary>
        public DbSet<WhInbound> WhInbound { get; set; }
        /// <summary>
        /// 销售退货明细
        /// </summary>
        public DbSet<OmSalesReturnDetail> OmSalesReturnDetail { get; set; }
        /// <summary>
        /// 盘点明细
        /// </summary>
        public DbSet<WhStockTakeDetail> WhStockTakeDetail { get; set; }
        /// <summary>
        /// 盘点
        /// </summary>
        public DbSet<WhStockTake> WhStockTake { get; set; }
        /// <summary>
        /// 调拨明细
        /// </summary>
        public DbSet<WhTransferDetail> WhTransferDetail { get; set; }
        /// <summary>
        /// 调拨
        /// </summary>
        public DbSet<WhTransfer> WhTransfer { get; set; }
        /// <summary>
        /// 出库
        /// </summary>
        public DbSet<WhOutbound> WhOutbound { get; set; }
        /// <summary>
        ///出库明细
        /// </summary>
        public DbSet<WhOutboundDetail> WhOutboundDetail { get; set; }
    }
}
